package com.hongx.zhibo;

import android.content.Context;
import android.util.Log;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import java.util.ArrayList;
import java.util.List;

public class MyItemAnimator extends SimpleItemAnimator {

    private final NewAdapter newAdapter;
    private final Context context;
    List<RecyclerView.ViewHolder> changleHolders = new ArrayList<>();
    List<RecyclerView.ViewHolder> changleAnimators = new ArrayList<>();

    public MyItemAnimator(NewAdapter newAdapter, Context context) {
        this.newAdapter = newAdapter;
        this.context = context;
    }

    @Override
    public boolean animateRemove(RecyclerView.ViewHolder holder) {
        return false;
    }

    @Override
    public boolean animateAdd(RecyclerView.ViewHolder holder) {
        return false;
    }

    @Override
    public boolean animateMove(RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY) {
        return false;
    }

    @Override
    public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, int fromLeft, int fromTop, int toLeft, int toTop) {
        Log.e("TAG", "animateChange: " + oldHolder.getLayoutPosition() + "----" + newHolder.getLayoutPosition());
        changleHolders.add(oldHolder);
        changle(oldHolder);
        return true;
    }

    private void changle(RecyclerView.ViewHolder viewHolder) {
        changleAnimators.add(viewHolder);
        TranslateAnimation inAnim = (TranslateAnimation) AnimationUtils.loadAnimation(context, R.anim.gift_in);
        inAnim.setDuration(500);

    }

    @Override
    public void runPendingAnimations() {

    }

    @Override
    public void endAnimation(@NonNull RecyclerView.ViewHolder item) {

    }

    @Override
    public void endAnimations() {

    }

    @Override
    public boolean isRunning() {
        return true;

    }
}
